from pydantic import BaseModel,Field,RootModel
from sanic import Blueprint
from sanic_ext import validate
from sanic import Request
from service.scrapy import GoodsSource,Page
from .res import json
from typing import List


router = Blueprint("GoodsManagement","/goods")

@router.get("/search")
async def search(request: Request,source: GoodsSource):
    return json(source.getGoodsList(currentPage=1))

@router.get("/sku")
async def sku(request: Request,source: GoodsSource):
    return json(source.getSKUImg(request.args.get("id")))

@router.get("/desc")
async def desc(request: Request,source: GoodsSource):
    return json(source.getDescImg(request.args.get("id")))

class MoveParams(BaseModel):
    ids: List[int] = Field(..., description="需要搬家的商品ID")
    
    
@router.get("/move")
@validate(json=MoveParams)
async def move(params: MoveParams):
    return params

